package com.yami.shop.multishop.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.dto.MeetingDto;
import com.yami.shop.bean.model.MeetingSign;
import com.yami.shop.bean.model.User;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.i18n.I18nMessage;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.common.service.AppConnectService;
import com.yami.shop.security.multishop.util.SecurityUtils;
import com.yami.shop.service.MeetingSignService;
import com.yami.shop.service.UserCancelService;
import com.yami.shop.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/shop/meetingSign")
@Tag(name = "会议签到接口")
@AllArgsConstructor
public class MeetingSignController {

    private final  MeetingSignService meetingSignService;

    @GetMapping("/page")
    @Operation(summary = "分页获取会议签到列表", description = "分页获取会议签到列表")
    public ServerResponseEntity<IPage<MeetingSign>> page(@ParameterObject MeetingSign meetingSign, PageParam<MeetingSign> page) {
        Long shopId = SecurityUtils.getShopUser().getShopId();
        IPage<MeetingSign> meetingPage = meetingSignService.page(page, new LambdaQueryWrapper<MeetingSign>()
                .eq(MeetingSign::getShopId, shopId)
                .eq(MeetingSign::getMeetingId, meetingSign.getMeetingId())
                .like(ObjectUtil.isNotEmpty(meetingSign.getTelephone()),MeetingSign::getTelephone,meetingSign.getTelephone())
                .orderByDesc(MeetingSign::getCreateTime));
        return ServerResponseEntity.success(meetingPage);
    }

    @GetMapping("/info/{meetingSignId}")
    @Operation(summary = "根据会议签到Id获取会议签到详情", description = "根据会议签到Id获取会议签到详情")
    public ServerResponseEntity<MeetingDto> info(@PathVariable("meetingSignId") Long meetingSignId) {
        MeetingSign meetingSign = meetingSignService.getMeetingSignById(meetingSignId);
        return ServerResponseEntity.success(BeanUtil.copyProperties(meetingSign, MeetingDto.class));
    }

    @GetMapping("/meetingSignList/{meetingId}")
    @Operation(summary = "根据会议Id获取会议签到列表", description = "根据会议Id获取会议签到列表")
    public ServerResponseEntity<List<MeetingSign>> meetingSignList(@PathVariable("meetingId") Long meetingId) {
        Long shopId = SecurityUtils.getShopUser().getShopId();
        List<MeetingSign> meetingSigns = meetingSignService.getMeetingSignByShopIdAndMeetingId(shopId,meetingId);
        return ServerResponseEntity.success(meetingSigns);
    }

}
